﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReadyApps.Data.Wiki
{
    /// <summary>
    /// Represents a link from one page to another page within the same system.
    /// </summary>
    /// <seealso cref="PageContent"/>
    public class InternalPageLink
    {
        #region Properties

        /// <summary>
        /// Gets the page ID of the page linked to by the wiki link.
        /// </summary>
        public int LinkPageID { get; private set; }

        /// <summary>
        /// Gets the unique wiki link identifier relative to the current page.
        /// </summary>
        public int PageLinkKey { get; private set; }

        /// <summary>
        /// Gets the full path to the page within the content hierarchy.
        /// </summary>
        public string FullPath { get; private set; }

        /// <summary>
        /// Gets the text to display for the wiki link.
        /// </summary>
        public string DisplayText { get; private set; }

        /// <summary>
        /// Gets the optional link target of the wiki link.
        /// </summary>
        public string Target { get; private set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Creates a new <see cref="InternalPageLink"/> object for the given properties.
        /// </summary>
        /// <param name="linkPageID">The page ID of the linked page.</param>
        /// <param name="pageLinkKey">The unique link number relative to the current page.</param>
        /// <param name="fullPath">The full path to the page.</param>
        /// <param name="displayText">The text to display for the link.</param>
        /// <param name="target">The optional link target.</param>
        public InternalPageLink(int linkPageID, int pageLinkKey, string fullPath, string displayText, string target)
        {
            LinkPageID = linkPageID;
            PageLinkKey = pageLinkKey;
            FullPath = fullPath;
            DisplayText = displayText;
            Target = target;
        }

        #endregion

        #region Method Overrides

        public override int GetHashCode()
        {
            unchecked // Don't worry about overflowing integer limits
            {
                int hash = 17;
                hash = hash * 23 + LinkPageID.GetHashCode();
                hash = hash * 23 + PageLinkKey.GetHashCode();
                hash = hash * 23 + FullPath.GetHashCode();
                hash = hash * 23 + DisplayText.GetHashCode();
                hash = hash * 23 + Target.GetHashCode();
                return hash;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            InternalPageLink other = (InternalPageLink)obj;
            return GetHashCode() == other.GetHashCode();
        }

        #endregion
    }
}
